<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Field_Data_Body_Entity extends CI_Model
{
    private $tablename = 'field_data_body';
    private $entity_type = null;
    private $bundle = null;
    private $deleted = null;
    private $entity_id = null;
    private $revision_id = null;
    private $language = null;
    private $delta = null;
    private $body_value = null;
    private $body_summary = null;
    private $body_format = null;
    
    public function setEntity_type($Entity_type)
    {
        $this->entity_type = $Entity_type;
    }

    public function setBundle($Bundle)
    {
        $this->bundle = $Bundle;
    }

    public function setDeleted($Deleted)
    {
        $this->deleted = $Deleted;
    }

    public function setEntity_id($Entity_id)
    {
        $this->entity_id = $Entity_id;
    }

    public function setRevision_id($Revision_id)
    {
        $this->revision_id = $Revision_id;
    }

    public function setLanguage($Language)
    {
        $this->language = $Language;
    }

    public function setDelta($Delta)
    {
        $this->delta = $Delta;
    }

    public function setBody_value($Body_value)
    {
        $this->body_value = $Body_value;
    }

    public function setBody_summary($Body_summary)
    {
        $this->body_summary = $Body_summary;
    }

    public function setBody_format($Body_format)
    {
        $this->body_format = $Body_format;
    }

    public function save()
    {
        $params = array();
        foreach ($this as $key => $val) {
            if ($key == 'tablename') continue;
            if ($val === null || $val === '') continue;
            $params[$key] = $val;
        }
                
        if (!isset($params['id'])) {
            if ($this->db->insert($this->tablename, $params)) {
                return $this->db->insert_id();
            } else {
                return 0;
            }
        } else {
            return $this->db->update($this->tablename, $params, array('id' => $params['id']));
        }
        
    }
    
    public function del($id)
    {
        
        return $this->db->delete($this->tablename, array('id' => $id));    
    }
    
    public function getField_Data_BodyById($id)
    {
        $query = $this->db->get_where($this->tablename, array('id' => $id));
        if ($query->num_rows() > 0) {
            return $query->row();
        }
        return false;
    }
    
    public function getAllList()
    {
        $query = $this->db->get($this->tablename);
        return $query->result();
    }
    
    public function TotalField_Data_Body()
    {
        $query = $this->db->count_all_results('Field_Data_Body'); 
        return $query->result();
    } 
}       
        